<?php

use App\Models\Category;
use App\Models\Post;
use App\Models\User;
use Illuminate\Database\Seeder;

class PostSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {

        $users = User::query()->pluck('id')->toArray();
        $category_ids = Category::query()->pluck('id')->toArray();
        $faker = app(Faker\Generator::class);
        $topics =  factory(Post::class)->times(10)->make()->each(function ($topic,$index) use($users,$category_ids,$faker){
            $topic->user_id = $faker->randomElement($users);
            $topic->category_id = $faker->randomElement($category_ids);
        });
        Post::query()->insert($topics->toArray());
    }
}
